package edu.stu.mall.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import edu.stu.mall.databinding.ItemClassificationLayoutBinding
import edu.stu.mall.databinding.ItemProductCategoryChildrenListBinding
import edu.stu.mall.repository.data.Children
import edu.stu.mall.repository.data.ItemModel
import edu.stu.mall.service.loadImage

class ProductCategoryChildrenListAdapter :
    RecyclerView.Adapter<ProductCategoryChildrenListAdapter.ProductCategoryChildrenListViewHolder>() {

    private var dataList: List<Children> = mutableListOf()
    fun setChildrenListData(list: List<Children>?) {
        if (list != null && list.isNotEmpty()) {
            dataList = list
            notifyDataSetChanged()
        }
    }


    class ProductCategoryChildrenListViewHolder(binding: ItemProductCategoryChildrenListBinding) :
        RecyclerView.ViewHolder(binding.root) {
        var itemBinding: ItemProductCategoryChildrenListBinding

        init {
            itemBinding = binding
        }
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ProductCategoryChildrenListViewHolder {

        return ProductCategoryChildrenListViewHolder(
            ItemProductCategoryChildrenListBinding.inflate(
                LayoutInflater.from(parent.context),
                parent, false
            )
        )
    }

    override fun getItemCount(): Int {
        return dataList.size

    }

    override fun onBindViewHolder(holder: ProductCategoryChildrenListViewHolder, position: Int) {
//        Glide.with(context).load(dataList[position].imageUrl).into(holder.itemBinding.imageView)

        val children = dataList[position]
        Log.e("TAG", "aaaaaaaaaaa: $children")

        holder.itemBinding.item = dataList[position]
        loadImage(dataList[position].icon, holder.itemBinding.imageView)

    }
}